package vk 
{
	import asunit.framework.TestCase;
  import flash.events.TimerEvent;
  import flash.utils.ByteArray;
  import flash.utils.Timer;
	
	/**
   * ...
   * @author Roman Marchenko
   */
  public class TestRemoteVars extends TestCase 
  {
    public function TestRemoteVars(testMethod:String = null) 
    {
      super(testMethod);
    }
    
    override protected function setUp () : void
    {
      Api.setUp(new Object); // empty vars array
    }
    
/*    
    public function testRemoteVarsSimple (): void
    {
      var key: String = "just_get";
      var obj: RemoteVars = new RemoteVars(new Object);
      obj.addEventListener(RemoteVarsEvent.OK_GETVAR, addAsync(null, 10000)); 
      obj.getVar(key);
    }

    public function testRemoteVarsPutSimple (): void
    {
      var key: String = "put_string";
      var str: String = "Это просто строка";
      
      var obj: RemoteVars = new RemoteVars(new Object);
      obj.addEventListener(RemoteVarsEvent.OK_PUTVAR, addAsync(null, 10000)); 
      
      obj.putVar(key, str.toString());
    }
*/
    public function testRemoteVarsPutGetUint (): void
    {
      var timerHandler: Function = function (e: TimerEvent): void
      {
        var key: String = "uint_value";
        var value: uint = 1;
      
        var puthandler: Function = function (key:String, value:String): void
        {
          var res: uint = uint(RemoteVars.getVar(key));
          assertEquals(value, res)
        }
      
        RemoteVars.putVar(key, value.toString(), addAsync(puthandler, 10000));
      }

      var t: uint = 1; // msec
      trace("TestRemoteVars.testRemoteVarsPutGetUint, timer=" + t);
      var timer: Timer = new Timer(t, 1);
      timer.addEventListener(TimerEvent.TIMER, addAsync(timerHandler, 20000));
      timer.start();
    }

    public function testRemoteVarsPutGetString (): void
    {
      var timerHandler: Function = function (e: TimerEvent): void
      {
        var key: String = "string_value";
        var value: String = "строчное значение переменной";
        var obj: RemoteVars = new RemoteVars;
      
        var puthandler: Function = function (key:String, value:String): void
        {
          var res: String = String(RemoteVars.getVar(key));
          assertEquals(value, res);
        }
      
        RemoteVars.putVar(key, value.toString(), addAsync(puthandler, 10000));
      }

      var t: uint = 10000; // msec
      trace("TestRemoteVars.testRemoteVarsPutGetString, timer=" + t);
      var timer: Timer = new Timer(t, 1);
      timer.addEventListener(TimerEvent.TIMER, addAsync(timerHandler, 20000));
      timer.start();
    }

  }

}